home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / OLE2BOOK.ZIP / BASICS.ZIP / CLASSLIB / CSTASTRP.CPP < prev    next >
C/C++ Source or Header  |  1993-03-16  |  7KB  |  343 lines

  1. /*
  2.  * CSTASTRP.C
  3.  * Sample Code Class Libraries
  4.  *
  5.  * C++ wrapper class for the StatStrip control
  6.  *
  7.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  8.  *
  9.  * Kraig Brockschmidt, Software Design Engineer
  10.  * Microsoft Systems Developer Relations
  11.  *
  12.  * Internet  :  kraigb@microsoft.com
  13.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  14.  */
  15.  
  16.  
  17. #include <windows.h>
  18. #include "classlib.h"
  19.  
  20.  
  21. /*
  22.  * CStatStrip::CStatStrip
  23.  * CStatStrip::~CStatStrip
  24.  *
  25.  * Constructor Parameters:
  26.  *  hInst           HINSTANCE of the module we're loaded in.
  27.  */
  28.  
  29. CStatStrip::CStatStrip(HINSTANCE hInst)
  30.     : CWindow(hInst)
  31.     {
  32.     return;
  33.     }
  34.  
  35.  
  36. CStatStrip::~CStatStrip(void)
  37.     {
  38.     return;
  39.     }
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46. /*
  47.  * CStatStrip::FInit
  48.  *
  49.  * Purpose:
  50.  *  Initializes a StatStrip object by creating the control that it owns.
  51.  *
  52.  * Parameters:
  53.  *  hWndParent      HWND of the parent window.  The StatStrip is created
  54.  *                  up from the bottom of this window, spanning the entire
  55.  *                  width of the window.
  56.  *  uID             UINT id of the control.
  57.  *  cy              UINT height to create the control
  58.  *
  59.  * Return Value:
  60.  *  BOOL            TRUE if the function succeeded, FALSE otherwise.
  61.  */
  62.  
  63. BOOL CStatStrip::FInit(HWND hWndParent, UINT uID, UINT cy)
  64.     {
  65.     RECT        rc;
  66.  
  67.     GetClientRect(hWndParent, &rc);
  68.  
  69.     m_cy=cy;
  70.     m_hWnd=CreateWindow(CLASS_STATSTRIP, "Ready"
  71.         , WS_CHILD | WS_VISIBLE, rc.left, rc.top, rc.right-rc.left, cy
  72.         , hWndParent, (HMENU)uID, m_hInst, 0L);
  73.  
  74.     return (NULL!=m_hWnd);
  75.     }
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. /*
  83.  * CStatStrip::OnSize
  84.  *
  85.  * Purpose:
  86.  *  Handles parent resizing.  The owner of this window is responsible
  87.  *  to call this function when it wants the StatStrip to resize.  The
  88.  *  StatStrip will automatically occupy a lower strip of CYSTATSTRIP high
  89.  *  on the bottom of the window.
  90.  *
  91.  * Parameters:
  92.  *  hWndParent      HWND of the parent window to which we're resizing.
  93.  *
  94.  * Return Value:
  95.  *  None
  96.  */
  97.  
  98. void CStatStrip::OnSize(HWND hWndParent)
  99.     {
  100.     RECT        rc;
  101.  
  102.     GetClientRect(hWndParent, &rc);
  103.  
  104.     SetWindowPos(m_hWnd, NULL, rc.left, rc.bottom-rc.top-CYSTATSTRIP
  105.         , rc.right-rc.left, m_cy, SWP_NOZORDER);
  106.  
  107.     return;
  108.     }
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116. /*
  117.  * CStatStrip::MessageSet
  118.  *
  119.  * Purpose:
  120.  *  Sets a message in the StatStrip explicitly with a string.
  121.  *
  122.  * Parameters:
  123.  *  pszMsg          LPSTR to the string to display.
  124.  *
  125.  * Return Value:
  126.  *  None
  127.  */
  128.  
  129. void CStatStrip::MessageSet(LPSTR psz)
  130.     {
  131.     SetWindowText(m_hWnd, psz);
  132.     return;
  133.     }
  134.  
  135.  
  136.  
  137.  
  138.  
  139. /*
  140.  * CStatStrip::MessageGet
  141.  *
  142.  * Purpose:
  143.  *  Retrieves the current message from the StatStrip
  144.  *
  145.  * Parameters:
  146.  *  psz             LPSTR in which to return the message.
  147.  *  cchMax          UINT maximum number of characters to copy.
  148.  *
  149.  * Return Value:
  150.  *  UINT            Number of characters copied.
  151.  */
  152.  
  153. UINT CStatStrip::MessageGet(LPSTR psz, UINT cchMax)
  154.     {
  155.     return GetWindowText(m_hWnd, psz, cchMax);
  156.     }
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163. /*
  164.  * CStatStrip::MessageGetLength
  165.  *
  166.  * Purpose:
  167.  *  Returns the length of the current message in the StatStrip.
  168.  *
  169.  * Parameters:
  170.  *  None
  171.  *
  172.  * Return Value:
  173.  *  UINT            Number of characters in the current message
  174.  */
  175.  
  176. UINT CStatStrip::MessageGetLength(void)
  177.     {
  178.     return GetWindowTextLength(m_hWnd);
  179.     }
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186. /*
  187.  * CStatStrip::FontSet
  188.  *
  189.  * Purpose:
  190.  *  Changes the font in the StatStrip.
  191.  *
  192.  * Parameters:
  193.  *  hFont           HFONT of the font to use in the control.
  194.  *  fRedraw         BOOL indicating if the control is to repaint or not.
  195.  *
  196.  * Return Value:
  197.  *  None
  198.  */
  199.  
  200. void CStatStrip::FontSet(HFONT hFont, BOOL fRedraw)
  201.     {
  202.     SendMessage(m_hWnd, WM_SETFONT, (WPARAM)hFont, (LPARAM)fRedraw);
  203.     return;
  204.     }
  205.  
  206.  
  207.  
  208.  
  209.  
  210. /*
  211.  * CStatStrip::FontGet
  212.  *
  213.  * Purpose:
  214.  *  Retrieves the handle of the current font used in the control.
  215.  *
  216.  * Parameters:
  217.  *  None
  218.  *
  219.  * Return Value:
  220.  *  HFONT           Handle to the current font.
  221.  */
  222.  
  223. HFONT CStatStrip::FontGet(void)
  224.     {
  225.     return (HFONT)(UINT)SendMessage(m_hWnd, WM_GETFONT, 0, 0L);
  226.     }
  227.  
  228.  
  229.  
  230.  
  231.  
  232. /*
  233.  * CStatStrip::Enable
  234.  *
  235.  * Purpose:
  236.  *  Enables or disables the StatStrip window, graying the text if the
  237.  *  control is disabled.
  238.  *
  239.  * Parameters:
  240.  *  fEnable         BOOL specifying to enable (TRUE) or disable (FALSE)
  241.  *
  242.  * Return Value:
  243.  *  None
  244.  */
  245.  
  246. void CStatStrip::Enable(BOOL fEnable)
  247.     {
  248.     EnableWindow(m_hWnd, fEnable);
  249.     return;
  250.     }
  251.  
  252.  
  253.  
  254.  
  255.  
  256. /*
  257.  * CStatStrip::MessageMap
  258.  *
  259.  * Purpose:
  260.  *  Initializes a CStatStrip for automated processing of WM_MENUSELECT
  261.  *  messages as well as setting up a list of messages that we can display
  262.  *  using identifiers instead of string pointers.  See MenuSelect and
  263.  *  MessageDisplay members.
  264.  *
  265.  * Parameters:
  266.  *  hWnd            HWND of the window owning menus we're interested in.
  267.  *  hInst           HINSTANCE of the application from which to load resources
  268.  *  uIDRMap         UINT identifying a resource mapping ID values to string
  269.  *                  ID values.
  270.  *  idsMin          UINT specifying the lowest string ID to load.
  271.  *  idsMax          UINT specifying the hightest string ID to load.
  272.  *  cchMax          UINT maximum string length.
  273.  *  uIDPopupMin     UINT identifying the lowest ID to assign to popup menus.
  274.  *  uIDPopupMax     UINT identifying the highest ID to assign to popup menus.
  275.  *  uIDStatic       UINT identifying the ID for the quiescent message.
  276.  *  uIDBlank        UINT identifying the ID for a blank message.
  277.  *  uIDSysMenu      UINT identifying the ID for the system menu.
  278.  *
  279.  * Return Value:
  280.  *  BOOL            TRUE if the function was successful, FALSE otherwise.
  281.  */
  282.  
  283. BOOL CStatStrip::MessageMap(HWND hWnd, HINSTANCE hInst, UINT uIDRMap
  284.     , UINT idsMin, UINT idsMax, UINT cchMax, UINT uIDPopupMin
  285.     , UINT uIDPopupMax, UINT uIDStatic, UINT uIDBlank, UINT uIDSysMenu)
  286.     {
  287.     //Initialize all the messages in the StatStrip
  288.     return StatStripMessageMap(m_hWnd, hWnd, hInst, uIDRMap, idsMin, idsMax
  289.         , cchMax, uIDPopupMin, uIDPopupMax, uIDStatic, uIDBlank, uIDSysMenu);
  290.     }
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297. /*
  298.  * CStatStrip::MenuSelect
  299.  *
  300.  * Purpose:
  301.  *  Displays the appropriate message for whatever is in the parameters
  302.  *  of a WM_MENUSELECT message.  This can only be called if
  303.  *  StatStripMessageMap has already been called and must be used with
  304.  *  the same menu the owner window had at the time of that call.
  305.  *
  306.  * Parameters:
  307.  *  wParam          WPARAM of the WM_MENUSELECT message.
  308.  *  lParam          LPARAM of the WM_MENUSELECT message.
  309.  *
  310.  * Return Value:
  311.  *  None
  312.  */
  313.  
  314. void CStatStrip::MenuSelect(WPARAM wParam, LPARAM lParam)
  315.     {
  316.     StatStripMenuSelect(m_hWnd, wParam, lParam);
  317.     return;
  318.     }
  319.  
  320.  
  321.  
  322.  
  323.  
  324. /*
  325.  * CStatStrip::MessageDisplay
  326.  *
  327.  * Purpose:
  328.  *  Displays the appropriate message for a given ID value.   This can
  329.  *  only be called if StatStripMessageMap has already been called.
  330.  *
  331.  * Parameters:
  332.  *  uID             UINT of the message to display.
  333.  *
  334.  * Return Value:
  335.  *  None
  336.  */
  337.  
  338. void CStatStrip::MessageDisplay(UINT uID)
  339.     {
  340.     StatStripMessageDisplay(m_hWnd, uID);
  341.     return;
  342.     }
  343.